﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DiagnosisToolBL;
using com.diagnosis.tool.bl;


namespace DiagnosisToolUI
{
    public partial class DiagnosisToolForm : Form
    {
        private IGetDiseases mGetDiseases = null;
        
        public DiagnosisToolForm()
        {
            InitializeComponent();

            mGetDiseases = GetDiseasesFactory.GetInterface(@"C:\projects\DiagnosisData.xml");
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            String newVal = textBoxSymptomVal.Text;

            if (null == newVal || newVal.Trim().Length == 0)
            {
                MessageBox.Show("Error! An empty value was inserted!");
                return;
            }

            listViewSymptoms.Items.Add(newVal);

            DoProcess();
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listViewSymptoms.SelectedItems)
            {
                listViewSymptoms.Items.Remove(item);
            }

            DoProcess();
        }

        private void btnProcess_Click(object sender, EventArgs e)
        {
            
        }

        private void DoProcess()
        {
            listViewFoundDiseases.Items.Clear();

            List<String> symptomsToCheck = new List<String>();

            foreach (ListViewItem item in listViewSymptoms.Items)
            {
                symptomsToCheck.Add(item.Text);
            }

            ExtendedDiseaseForDisplay[] foundDiseases = mGetDiseases.GetDiseases(symptomsToCheck.ToArray());

            foreach (var curFoundDisease in foundDiseases)
            {
                listViewFoundDiseases.Items.Add(curFoundDisease.ToString());
            }
        }
    }
}
